package com.lujianfei.mqtt.login.mvvm


import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import retrofit2.Call
import retrofit2.http.*

/**
 * @Author: wn
 * @Date: 2024/4/15 16:01
 * @Description: 登陆的 API 接口 retrofit
 */
interface LoginService {
  /**
   * 校验用户是否存在
   * @param {String} account - 帐号
   * @returns promise
   */
  @GET("register/check")
  suspend fun isRegister(@Query("account") account: String): BaseResponse<RegisterRsp>

  /**
   * 登陆
   * @param reqBody LoginReq -- account password
   * @return NetResponse
   */
  @POST("/login")
  suspend fun login(@Body reqBody: LoginReq): BaseResponse<UserInfo>
}

data class BaseResponse<T>(
  val code: Int,// 响应码
  val data: T,// 数据
  val msg: String?,// 结果描述
){
  companion object{
    const val SERVER_CODE_FAILED = 500 // 接口请求响应业务处理 失败
    const val SERVER_CODE_SUCCESS = 200 // 接口请求响应业务处理 成功
  }
}

data class RegisterRsp(
  val valid: Boolean, // true 表示注册 false表示未注册
)

/**
 * @Author: wn
 * @Date: 2024/4/15 16:13
 * @Description: 登录模块相关的请求 数据类
 */
data class LoginReq(
  val account: String, // 手机号
  val password: String, // 密码
  val color: String ="",
  val id: String ="",
  val isAdmin: String ="",
  val name: String ="",
  val teamId: String ="",
  val teamName: String ="",
)

@Parcelize
data class UserInfo(
  val id: String,
  val name: String,
  val account: String,
  val password: String?,
  val teamId: String,
  val teamName: String,
  val color: String,
  val isAdmin: String,
) : Parcelable